# Create your views here.

from django.template import Context, loader
from django.http import HttpResponse
from django import forms

from settings import DIRS, MODULES
import model_recommendation_xml as recommendations

menu = {"Manage Messages": {"status": "inactive", "short_name": "Messa...", "url": "/recommendation/manage_messages/"}, 
        "Manage Messages Types": {"status": "inactive", "short_name": "Types", "url": "/recommendation/manage_types/"}}

TEMPLATES_MEDIA_URL = DIRS["PROJECT_MEDIA_URL"] + 'myTemplates/snow-flakes/'
recommendation = recommendations.Recommendations()


#configurar active en grafico
def link_activated(list_links, key):
    for list_link in list_links:
        if list_link.lower().replace(" ", "_") == key.lower().replace(" ", "_"):
            list_links[list_link]["status"] = "active"
        else: list_links[list_link]["status"] = "inactive"

link_activated(MODULES, 'Iasna Recommendation')

def index(request):
    link_activated(menu, '')
    
    title = 'IASNA Recommendation'
    subtitle = '' 
    welcome = 'Welcome to IASNA_Recommendation module. Here you can add, modify and delete any recommendation message for Collaborative Learning sessions.'
    
    t = loader.get_template('recommendation1.html')
    c = Context({
        'title': title,
        'subtitle': subtitle,
        'welcome': welcome,
        'menu': menu,
        'modules': MODULES,
        'TEMPLATES_MEDIA_URL': TEMPLATES_MEDIA_URL,
    })
    return HttpResponse(t.render(c))

class Manage_messages(forms.Form):
    choices = (('0.0', 0.0), ('0.1', 0.1), ('0.2', 0.2), ('0.3', 0.3), ('0.4', 0.4), ('0.5', 0.5), 
               ('0.6', 0.6), ('0.7', 0.7), ('0.8', 0.8), ('0.9', 0.9), ('1.0', 1.0), )
    
    From = forms.ChoiceField( choices )
    To = forms.ChoiceField( choices )
    Type_message = forms.ChoiceField( recommendation.message_type_get_all() )
    Message = forms.CharField( max_length = 100 )

def manege_messages(request):
    link_activated(menu, 'Manage Messages')
    
    title = 'IASNA Recommendation: manage messages'
    subtitle = 'Manage messages' 
    manage = Manage_messages()

    t = loader.get_template('recommendation1.html')
    c = Context({
        'title': title,
        'subtitle': subtitle,
        'menu': menu,
        'manage': manage,
        'modules': MODULES,
        'TEMPLATES_MEDIA_URL': TEMPLATES_MEDIA_URL,
    })
    return HttpResponse(t.render(c))

def manage_types(request):
    link_activated(menu, 'Manage Messages Types')
    
    title = 'IASNA Recommendation: manage message types'
    subtitle = 'Manage message types' 

    t = loader.get_template('recommendation1.html')
    c = Context({
        'title': title,
        'subtitle': subtitle,
        'menu': menu,
        'modules': MODULES,
        'TEMPLATES_MEDIA_URL': TEMPLATES_MEDIA_URL,
    })
    return HttpResponse(t.render(c))

